package liumengbaio.lolzhangyoubao.Activity.utils;

import android.content.Context;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.InFo.EquipInfo;

/**
 * 获取装备的方法
 * Created by lanouhn on 16/9/19.
 */
public class EquipUtils {


    public static List<EquipInfo> getEquipInfo(Context mContext) {

        List<EquipInfo> lists = new ArrayList<>();
        try {
            InputStream is = mContext.getAssets().open("equip/equipitems.json");
            byte[] buffer = new byte[is.available()];
            is.read(buffer);
            is.close();

            String text = new String(buffer, "UTF-8");
            JSONObject mObject = new JSONObject(text);
            JSONArray mArray = mObject.getJSONArray("data");
/**
 * 获取本地数据
 */
            for (int i = 0; i < mArray.length(); i++) {
                EquipInfo list = new EquipInfo();
                JSONObject object = mArray.getJSONObject(i);
                list.setId(object.getString("id"));
                list.setName(object.getString("name"));
                list.setArea(object.getString("area"));
                list.setAttr(object.getString("attr"));
                list.setPrice(object.getString("price"));
                list.setBy_id(object.getString("by_id"));
                list.setFor_id(object.getString("for_id"));
                list.setTprice(object.getString("tprice"));
                list.setFilter(object.getString("filter"));
                list.setPic_url(object.getString("pic_url"));
                lists.add(list);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lists;
    }
}
